package App.Job;

import App.Model.Account.CrmUser;
import App.Model.JPush.JPushCustomerContent;
import App.Repository.AccountRepository;
import App.Repository.TaskRepository;
import App.Service.JPushService;
import App.Service.XingeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by xw on 2019/8/29.
 */


@Component
public class LawyerMessageJob {


    @Autowired
    private AccountRepository _accountRepository;

    @Autowired
    private XingeService _xingeService;

    @Autowired
    private JPushService _jPushService;

    public void execute() {

        String _messageTemplate = "快下班咯，请尽快处理今日工作！";

        List<CrmUser> _users = _accountRepository.GetAuthUsers();
        for (CrmUser u : _users) {
            int userid = u.getId();
            String _userName = u.getRealname();

            List<String> _userids = new ArrayList<>();
            _userids.add(Integer.toString(userid));
            String _title = _userName;

            try {

                Collection<String> alias = new LinkedList<String>();
                alias.add(u.getUsername());
                JPushCustomerContent cc = new JPushCustomerContent();
                cc.setKey("e1117369b0a39e42185042aa");
                cc.setProjectid("3a95002c4cfe848816fc18db");
                cc.setPushType("ReminderAlert");

                //极光推送
                _jPushService.sendPushByAliasCustomer(alias, _title, _messageTemplate, cc);
                //信鸽推送
                _xingeService.pushMessage("", "", _userids, _title, _messageTemplate, "ReminderAlert");
            } catch (Exception ex){

            }
        }
    }


}
